<?php
require_once APP_DIR . 'user.php';  
require_once APP_DIR . 'mysql.php'; 
require_once APP_DIR . 'request.php';
//require_once APP_DIR . 'response.php'; 
require_once APP_DIR . 'session.php'; 
require_once APP_DIR . 'cookie.php';    
    
$db         = new MySQL($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']);
$request    = new Request();
//$response   = new Response();
$session    = new Session();
$cookie     = new Cookie();
$user       = new User($db, $request, $session); 

// Set all config to db
if(USE_DB_CONFIG){
    $query = $db->query("SELECT * FROM " . DB_PREFIX . "setting WHERE `group` = 'config'"); 
    $settings = array();
    foreach($query->rows as $item){
        $settings[$item['key']] = $item['value'];
    }

    $db_config = array(
        'page_limit'        => 'config_admin_limit'    ,
        
        'mail_protocol'     => 'config_mail_protocol', 
        'mail_parameter'    => 'config_mail_parameter',
        'smtp_host'         => 'config_smtp_host',
        'smtp_username'     => 'config_smtp_username',
        'smtp_password'     => 'config_smtp_password',
        'smtp_port'         => 'config_smtp_port',
        'smtp_timeout'      => 'config_smtp_timeout',  

        'name'              => 'config_name',
        'address'           => 'config_address',
        'phone'             => 'config_email',
        'fax'               => 'config_fax',
        'email'             => 'config_email',
        'system_name'       => 'config_owner',
        'system_address'    => ''  
    );

    foreach($db_config as $key => $value){
        if(isset($settings[$value])){
            $config[$key] = $settings[$value];
        }
    }
}